import Mock from 'mockjs2';
import {builder, getBody} from '../util';

const username = ['admin', 'super'];
const password = ['8914de686ab28dc22f30d3d8e107ff6c', '21232f297a57a5a743894a0e4a801fc3']; // admin, ant.design

const login = (options) => {
  const body = getBody(options);
  if (!username.includes(body.username) || !password.includes(body.password)) {
    return builder({isLogin: true}, '账户或密码错误', 401);
  }

  return builder(
    {
      id: Mock.mock('@guid'),
      name: Mock.mock('@name'),
      username: 'admin',
      password: '',
      status: 1,
      creatorId: 'admin',
      deleted: 0,
      roleId: 'admin',
      lang: 'zh-CN',
      token: '4291d7da9005377ec9aec4a71ea837f'
    },
    '',
    200,
    {'Custom-Header': Mock.mock('@guid')}
  );
};

const logout = () => {
  return builder({}, '[测试接口] 注销成功');
};

const smsCaptcha = () => {
  return builder({captcha: Mock.mock('@integer(10000, 99999)')});
};

const twofactor = () => {
  return builder({stepCode: Mock.mock('@integer(0, 1)')});
};

Mock.mock(/\/auth\/login/, 'post', login);
Mock.mock(/\/auth\/logout/, 'post', logout);
Mock.mock(/\/account\/sms/, 'post', smsCaptcha);
Mock.mock(/\/auth\/2step-code/, 'post', twofactor);
